package cn.stylefeng.guns.modular.packreview.service.impl;

import cn.stylefeng.guns.base.pojo.page.LayuiPageFactory;
import cn.stylefeng.guns.base.pojo.page.LayuiPageInfo;
import cn.stylefeng.guns.modular.packreview.entity.PackReviewDetails;
import cn.stylefeng.guns.modular.packreview.mapper.PackReviewDetailsMapper;
import cn.stylefeng.guns.modular.packreview.model.params.PackReviewDetailsParam;
import cn.stylefeng.guns.modular.packreview.model.result.PackReviewDetailsResult;
import  cn.stylefeng.guns.modular.packreview.service.PackReviewDetailsService;
import cn.stylefeng.roses.core.util.ToolUtil;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.io.Serializable;
import java.util.List;

/**
 * <p>
 * 打包复核详情 服务实现类
 * </p>
 *
 * @author wp
 * @since 2025-07-05
 */
@Service
public class PackReviewDetailsServiceImpl extends ServiceImpl<PackReviewDetailsMapper, PackReviewDetails> implements PackReviewDetailsService {

    @Override
    public void add(PackReviewDetailsParam param){
        PackReviewDetails entity = getEntity(param);
        this.save(entity);
    }

    @Override
    public void delete(PackReviewDetailsParam param){
        this.removeById(getKey(param));
    }

    @Override
    public void update(PackReviewDetailsParam param){
        PackReviewDetails oldEntity = getOldEntity(param);
        PackReviewDetails newEntity = getEntity(param);
        ToolUtil.copyProperties(newEntity, oldEntity);
        this.updateById(newEntity);
    }

    @Override
    public PackReviewDetailsResult findBySpec(PackReviewDetailsParam param){
        return null;
    }

    @Override
    public List<PackReviewDetailsResult> findListBySpec(PackReviewDetailsParam param){
        return this.baseMapper.customList(param);
    }

    @Override
    public LayuiPageInfo findPageBySpec(PackReviewDetailsParam param,String condition){
        Page pageContext = getPageContext();
        IPage page = this.baseMapper.customPageList(pageContext, param,condition);
        return LayuiPageFactory.createPageInfo(page);
    }

    @Override
    public void updatebyTrackNumberAndPickNumber(PackReviewDetailsParam packReviewDetailsParam) {
        this.baseMapper.updatebyTrackNumberAndPickNumber(packReviewDetailsParam);
    }

    @Override
    public void revokePackReviewGoods(PackReviewDetailsParam packReviewDetailsParam) {
        this.baseMapper.revokePackReviewGoods(packReviewDetailsParam);
    }

    @Override
    public void insertPackReviewDetails(PackReviewDetails packReviewDetailsList) {
        this.baseMapper.insertPackReviewDetails(packReviewDetailsList);
    }

    private Serializable getKey(PackReviewDetailsParam param){
        return param.getId();
    }

    private Page getPageContext() {
        return LayuiPageFactory.defaultPage();
    }

    private PackReviewDetails getOldEntity(PackReviewDetailsParam param) {
        return this.getById(getKey(param));
    }

    private PackReviewDetails getEntity(PackReviewDetailsParam param) {
        PackReviewDetails entity = new PackReviewDetails();
        ToolUtil.copyProperties(param, entity);
        return entity;
    }

}
